<template>
<view>
	<view class="wrap">
		<u-back-top :scroll-top="scrollTop"></u-back-top>
	</view>
	<u-loading-icon text="加载中..." textSize="18" :show="jiazai" ></u-loading-icon>
	<u-navbar :bgColor="bgColor" :placeholder="true">
		<view
			class="u-nav-slot d-buhuanhang"
			slot="left"
		>
			<u-icon
				name="arrow-left"
				size="22"
				@click="fanhui()"
			></u-icon>
			<view class="d-buhuanhang d-zuo-10 animated fadeInDown" v-if="scrollTop > 100">
				<view class="d-gaokuang-40 d-kuanggao-20 d-yuanjiao-40 d-box">
					<image v-if="tieziindex.touxiang" :src="tieziindex.touxiang" mode="aspectFill" class="d-img-26 d-yuanjiao-50 d-beijing-hui"></image>
					<image v-else src="/static/assets/images/avatar.png" mode="aspectFill" class="d-img-26 d-yuanjiao-50 d-beijing-hui"></image>
				</view>
				<view class="d-zuo-10">
					<view class="d-wenzi-14 d-jiacu">{{tieziindex.mingcheng}}</view>
				</view>
				<view class="d-kuan-80 d-zuo-10 d-neirong-you" :id="'guanzhu'+tieziindex.uid">
					<view v-if="guanzhuuid == 1" @click="getGuanzhus(1,tieziindex.uid)" class="d-kuan-50 d-beijing-hei d-wenzi-yanse-bai-0 d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >已关注</view>
					<view v-else @click="getGuanzhus(1,tieziindex.uid)" class="d-kuan-50 d-beijing-hui-f6 d-wenzi-hei d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >关 注</view>
				</view>
			</view>
			
		</view>
	</u-navbar>
	<!-- 帖子 -->
<view v-if="tiezijiazai" class="d-kuan ">
	
	<!-- 标题 -->
	<view v-if="tiezineirong.title" class="entry-title d-waikuang-10">{{tiezineirong.title}}</view>
	<!-- 头像 -->
	<view class="d-waikuang-10 d-buhuanhang">
		<!--头像-->
		<view class="d-gaokuang-40 d-kuanggao-40 d-yuanjiao-40 d-box"  @click="getgeren(tieziindex.uid)">
			<image v-if="tieziindex.touxiang" :src="tieziindex.touxiang" mode="aspectFill" class="d-img-40 d-yuanjiao-50 d-beijing-hui"></image>
			<image v-else src="/static/assets/images/avatar.png" mode="aspectFill" class="d-img-40 d-yuanjiao-50 d-beijing-hui"></image>
			<image v-if="rzs == 1" :src="v" mode="aspectFill" class="d-img-10 d-yuanjiao-50  d-box-xia"></image>
		</view>
		<view class="d-kuan d-zuo-10" @click="getgeren(tieziindex.uid)">
			<view class="d-wenzi-14 d-jiacu">{{tieziindex.mingcheng}}</view>
			<view class="d-wenzi-14 d-wenzi-yanse-hui">{{tieziindex.yonghuzu}}. {{tieziindex.guishudi}}</view>
		</view>
		<view class="d-kuan-80 d-neirong-you" :id="'guanzhu'+tieziindex.uid">
			<view v-if="guanzhuuid == 1" @click="getGuanzhus(1,tieziindex.uid)" class="d-kuan-50 d-beijing-hei d-wenzi-yanse-bai-0 d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >已关注</view>
			<view v-else @click="getGuanzhus(1,tieziindex.uid)" class="d-kuan-50 d-beijing-hui-f6 d-wenzi-hei d-neikuang-zuoyou-2-shangxia-4 d-wenzi-12 d-yuanjiao-50 d-neirong-juzhong" >关 注</view>
		</view>
	</view>
	<!-- 内容 -->
	<view class="d-waikuang-10" v-if="unshenhe == 0">
		<u-alert :title="title" type = "warning" :show-icon="true" description = "帖子审核中..."></u-alert>
	</view>
	<view v-if="unshenhe == 1 || tiezineirong.member && tiezineirong.member.is_admin ==1">
		<view class="d-waikuang-10">
			<jyf-parser :html="tieneirong"   :use-cache="true"></jyf-parser>
		</view>
		<!--九格图片-->
		<!--帖子内容图片-->
		<view class="d-zuoyou-neikuang-10">
			<view class="d-fu-kuan-10" >
				<block v-for="(itemtu, indextu) in tiezineirong.jiugetu" :key="indextu">
					<view class="d-kuan-30 d-zuo d-liangbian-10">
						<image :src="itemtu.url" mode="aspectFill" @click="showimgs(indextu)" class="d-img-100-bai d-yuanjiao-6 d-yinying-10"></image>
					</view>
				</block>
				<view class="d-clear"></view>
			</view>
		</view>
		<!--下载-->
		<view class="d-waikuang-10">
			<view class="" >
				<Dxiazai
					v-if="tiezineirong.xzzt ==1"
					:urlzhi="1"
					:xzzt="tiezineirong.xzzt"
					:xiazaifujian ="tiezineirong.xiazaifujian"
					:acid="tiezineirong.cid"
					:aid="tiezineirong.id"
					@xiazaifujian="xiazaifujian"
					@fujianurl = "fujianurl"
					@yunurl="yunurl"
					:yunxiazai="tiezineirong.yunxiazai"
				></Dxiazai>
			</view>
		</view>
		<view class="d-waikuang-10">
			<view class="d-kuan d-yuanjiao-10 d-shangxia-neikuang-10">
				<!--需求进度条-->
				<view v-if="jindu.xuqiukaiguan ==1" class="d-neikuang-10 d-shang-10  d-yuanjiao-10 " style="background-color: #f5f9ff;">
					<u-steps :current="jindu.xuqiu" beijing="#f5f9ff" inactiveColor="#adadad">
						<u-steps-item title="提需求" :desc="jindu.tixuqiutime"></u-steps-item>
						<u-steps-item title="排期中" :desc="jindu.paixuqiutime"></u-steps-item>
						<u-steps-item title="在开发" :desc="jindu.kaifaxuqiutime"></u-steps-item>
						<u-steps-item title="已上线" :desc="jindu.wangchengxuqiutime"></u-steps-item>
					</u-steps>
				</view>
				<!--缺点修复进度-->
				<view v-if="jindu.bugkaiguan ==1" class="d-neikuang-10 d-shang-10  d-yuanjiao-10 " style="background-color: #eefffa;">
					<u-steps :current="jindu.bugs" beijing="#eefffa" activeColor="#5eb295" inactiveColor="#adadad">
						<u-steps-item title="发现BUG" :desc="jindu.tibugtime"></u-steps-item>
						<u-steps-item title="排期中" :desc="jindu.paixubugtime"></u-steps-item>
						<u-steps-item title="在开发" :desc="jindu.kaifabugtime"></u-steps-item>
						<u-steps-item title="已修复" :desc="jindu.wangchengbugtime"></u-steps-item>
					</u-steps>
				</view>
			</view>
		</view>
	
	
		<!--点赞分享-->
		<view class="d-waikuang-10">
			<u-row justify="space-between">
				<u-col span="4">
					<view class="demo-layout bg-purple"></view>
				</u-col>
				<u-col span="4">
					<view class="d-kuan d-zyouyou-juzhong">
						<view class="d-bian-1 d-yuanjiao-50 d-neikuang-5 d-buhuanhang" @click="getZan(tieids,uid)">
							<view class="d-zuo-10 d-you-10 ">{{dianzanshu}}</view>
							<u-icon :name="dianzan" color="#ea521f" size="20"  labelPos="bottom" labelSize="12"></u-icon>
						</view>
					</view>
				</u-col>
				<u-col span="4">
					<view class="demo-layout bg-purple"></view>
				</u-col>
			</u-row>
		</view>
	
		<view class="d-waikuang-10" v-if="dianzandata.length > 0">

			<u-row justify="space-between">
				
				<u-col span="12">
					<view class="d-kuan d-zyouyou-juzhong">
						
						<view class="d-touxiang-10" v-for="(item, index) in dianzandata" :key="index">
							<u-avatar :src="item.touxiang" fontSize="22" size="20" ></u-avatar>
						</view>

					</view>
				</u-col>
				
			</u-row>
		</view>
	</view>
	<u-gap height="50" bgColor="#ffffff"></u-gap>
	<!--举报-->
	<u-row justify="space-between">
		<u-col span="6">
			<view class="d-kuan-140">
				<view class="d-zuo-10 d-bian-1 d-yuanjiao-50 d-neikuang-5 d-buhuanhang" @click="getQuan(tiezineirong.index.quanid)">
					<u-icon name="map" color="#c8c8c8" size="20"  labelPos="bottom" labelSize="12"></u-icon>
				    <view class="d-zuo-10 d-you-10 d-chaochu-1 d-wenzi-yanse-hui d-wenzi-14">{{tiezineirong.index && tiezineirong.index.quantitle}}</view>
				</view>
			</view>
		</u-col>
		<u-col span="6">
			<view class="d-kuan">
				<view class="d-kuan-70" style="float: right;justify-content: flex-end;">
					<u-icon name="bell" color="#919191" label="举报" size="28" @click="jubaoopen()"></u-icon>
				</view>
			</view>
		</u-col>
	</u-row>
	
	<u-popup :show="jubaoshow" mode="bottom" :round="10" @close="jubaoclose" @open="jubaoopen">
		<view style="height: 240px;">
			<view class="d-waikuang-10">
				<view class="">
					<uni-forms
						:modelValue="jubaoData" 
						label-position="top"
					>
						<u-cell icon="bell" title="帖子举报" value="填写内容"></u-cell>
					    <u--textarea v-model="jubaoData.neirong" placeholder="请输入内容" ></u--textarea>
						<view class="d-shang-10">
						<u-checkbox-group v-model="jubaoData.leixing" placement="row" @change="checkboxChange">
							<u-checkbox
								:customStyle="{marginBottom: '8px',paddingRight:'10px'}"
								v-for="(item, index) in jubaoList"
								:key="index"
								:label="item.name"
								:name="item.name"
								:disabled="item.disabled"
								:value="index"
							>
							</u-checkbox>
						</u-checkbox-group>
						</view>
						<view class="d-shang-10">
							<u-button type="primary" text="提交" @click="postJubaodata(tiezineirong.id)"></u-button>
						</view>
					</uni-forms>
					
				</view>
			</view>
		</view>
	</u-popup>
	<!--评论-->
	<view class="d-waikuang-10" v-if="unshenhe == 0">
		<view v-if="tiezineirong.member && tiezineirong.member.is_admin ==1">
			<u-tabbar
				:value="shehea"
				@change="shenhe"
				:fixed="true"
				:placeholder="false"
				:safeAreaInsetBottom="false"
			>
				<u-tabbar-item text="返回" icon="arrow-left" @click="fanhui()"></u-tabbar-item>
				<u-tabbar-item text="审核通过" icon="checkmark"></u-tabbar-item>
			</u-tabbar>
		</view>
	</view>
	<view v-else>
		<d-comment
			ref="hbComment" 
			@add="add" 
			@del="del" 
			@like="like"
			@getZan="getZan" 
			@getShoucang="getShoucang" 
			@focusOn="focusOn"
			@pingluncontent="pingluncontent"
			:pingluntongji="pingluntongji"
			:tieziindex="tieziindex"
			:deleteTip="'确认删除？'"
			:cmData="tiezi" 
			:dianzan="dianzan"
			:shoucang="shoucang"
			v-if="tiezi"
		>
		</d-comment>
	</view>
	<!--xia50-->
	<view class="d-kuan d-gao-100"></view>

<view>

	<u-modal 
		:show="shenheshow" 
		cancelText="取消" 
		confirmText="确认"
		:showCancelButton="true" 
		title="审核帖子" 
		content='确认核对通过' 
		@cancel="shenheguanbi"
		@confirm="shenhequerren"
	></u-modal>
	

	<view class="ditail-copyright" :style="'display:' + display">
		<block data-type="template" data-is="tempCopyright" data-attr="webSiteName:webSiteName,domain:domain">
			<view> {{webSiteName}} </view>
		</block>
	</view>

	<!-- 无法访问网络时 -->
	<view class="showerror" :style="'display:' + showerror">
		<!--image src="/static/images/cry80.png" style="height:100rpx;width:100rpx"></image-->
		<view class="errortext">{{errMessage}}</view>
	</view>

</view>
</view>
</view>
</template>

<script>

import config from "../../utils/config";
import Dxiazai from "@/components/d-xiazai/d-xiazai";  //引入组件
var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
const innerAudioContext = uni.createInnerAudioContext();
let isFocusing = false;
const pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
var defaultskin = config.getskin;
let rewardedVideoAd = null;
var wss = config.getWss;

export default {
  data() {
    return {
      detail: {
        content: {
          rendered: ""
        },
        title: {},
        acf: {}
      },
      content: {
        rendered: ""
      },
      title: '',
      acf: {},
      defaultskin: defaultskin,
      skin: defaultskin,
      //title: '文章内容',
      webSiteName: webSiteName,
      html: " ",
      detailDate: '',
      display: 'none',
      showerror: 'none',
      page: 1,
      isLastPage: false,
      parentID: "0",
      scrollHeight: 0,
      xiangguan: [],
      link: '',
      dialog: {
        title: '',
        content: '',
        hidden: true
      },
      content: '',
      flag: 1,
	   tagStyle: {
	      img: "height:auto!important;display:block"
	    },
      enableComment: true,
      isLoading: false,
      total_comments: 0,
      userInfo: {},
      shareImagePath: '',
      fristOpen: false,
      domain: domain,
      platform: '',
      tagStyle: {},
      errMessage: "",
      commentCount: "",
      likeCount: "",
      postID: "",
      postImageUrl: "",
      commentsList: "",
      article_article: "",
	  tiezi: [],
	  tieziindex:{},
	  tiezineirong: {},
	  jiazai:true,
	  tiezijiazai:false,
	  pinglun: [],
	  pingluntongji: 0,
	  tieids: '',
	  "reqFlag": false ,// 请求标志，防止重复操作，true表示请求中
	  member:'',
	  userInfo: '',
	  memberuid: '',
	  dianzan:'',
	  shoucang:'',
	  pingluncontents:'',
	  tieneirong:'',
	  rzs:'',
	  v:config.getDomain+'/static/default/web/img/V.png',
	  tieziuid:'',
	  guanzhuuid:'',
	  jindu:[],
	  jubaoshow :false,
	  jubaoData:{},
	  jubaotitle:'',
	  jubaoList: [{
		      id:1,
			  name: '广告',
			  disabled: false
		  },
		  {
			id:2,
			  name: '重复',
			  disabled: false
		  },
		  {
			  id:3,
			  name: '低俗',
			  disabled: false
		  },
		  {
			  id:4,
			  name: '夸张',
			  disabled: false
		  }
		  
	  ],
	  uid:'',
	  tongji:{},
	  jubaoshuju:{},
	  jubaoxuanzedata:{},
	  qid:'',
	  scrollTop: 0,
	  bgColor: '#ffffff',
	  dianzanshu:'0',
	  dianzandata:{},
	  shehea:0,
	  shenheshow:false,
	  keycode:'',
	  unshenhe:'1'
    };
  },

  components: {
	  Dxiazai
  },
  props: {},
  onPageScroll(e) {
  	this.scrollTop = e.scrollTop;
	//console.log("scrollTop",e.scrollTop);
  },
  onShow: function (options) {
    var that = this;
    var skin = uni.getStorageSync('skin');

    if (skin != '') {
      that.setData({
        skin: skin
      });
    }
	
  },
  onLoad: function (options) {
	  
    var duixin = this;
	duixin.tieids = options.id;
	duixin.qid = options.qid;
	//duixin.gundong();
    var skin = uni.getStorageSync('skin');
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	var keycode = uni.getStorageSync('keycode');
	duixin.keycode = keycode;
	//console.log("options",options);
	if (userInfo) {
		var member = uni.getStorageSync('member');
		var memberuid = uni.getStorageSync('memberuid');
		duixin.member = member;
		duixin.userInfo = userInfo;
		duixin.memberuid = memberuid;
		duixin.uid = memberuid;
		duixin.getimin(memberuid,member);
		
	}
	
	//duixin.getTieziid(options.qid,options.id,memberuid,userInfo);
	duixin.getPinglunNeirong(options.id,memberuid,userInfo);
	duixin.getTiezineirong(options.id,memberuid,userInfo);
	//console.log('duixin.tieziindex000: ',duixin.tieziindex);
	duixin.getJindus(options.id);
	duixin.getZanzhi(options.id);
	duixin.getShoucangzhi(options.id);
	duixin.getDangqianurl();
	duixin.getDianzantongjideta();

	
	
    if (skin != '') {
      duixin.setData({
        skin: skin
      });
    }
	
	
  },
  onShow: function () {
  	  //判断用户是否登录
  	  var userInfo = uni.getStorageSync('userInfo');
  	  var member = uni.getStorageSync('member');
  	  if (userInfo) {
  		  this.getTongjis(this.uid);
  		  this.getimin(this.uid,member);
  	  }
  },
  onUnload: function () {},
  //分享到个人朋友圈
  onShareAppMessage: function (res) {
    return {
      title: this.tiezineirong.title,
      path: 'pages/tiezi/tiezi?id=' + this.tiezineirong.index.id + '&qid=' + this.tiezineirong.index.cid,
      //imageUrl: this.tiezineirong.post_full_image,
      success: function (res) {
        // 转发成功
        //console.log(res);
      },
      fail: function (res) {
        //console.log(res); // 转发失败
      }
    };
  },
  //分享到朋友圈
  onShareTimeline: function (res) {
  	  return {
  	    title: this.tiezineirong.title,
  	    path: 'pages/tiezi/tiezi?id=' + this.tiezineirong.index.id + '&qid=' + this.tiezineirong.index.cid,
		imageUrl: this.tiezineirong.title,
  	    success: function (res) {// 转发成功
  	    },
  	    fail: function (res) {// 转发失败
  	    }
  	  };
  },
  methods: {
    BackPage() {
      uni.navigateBack({
        delta: 1
      });
    },
	fanhui() {
		const pages = getCurrentPages();  //判断跳转了多少页
		if (pages.length === 2) {  
			uni.navigateBack({
				delta: 1
			});
		} else if (pages.length === 1) { //如果没有上一页返回首页
			uni.switchTab({
				url: '/pages/index/index',
			})
		} else {
			uni.navigateBack({
				delta: 1
			});
		}
		
	},

    toHome() {
      uni.reLaunch({
        url: '/pages/index/index'
      });
    },

    gotowebpage: function () {
      var self = this;
      var url = '../webpage/webpage';
      uni.navigateTo({
        url: url + '?url=' + self.link
      });
    },
    copyLink: function (url) {
      uni.setClipboardData({
        data: url,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '链接已复制',
                image: "/static/images/uploads/link.png",
                duration: 2000
              });
            }
          });
        }
      });
    },
    copyText: function (e) {
      console.log(e);
      uni.setClipboardData({
        data: e.currentTarget.dataset.text,
        success: function (res) {
          uni.getClipboardData({
            success: function (res) {
              uni.showToast({
                title: '复制成功'
              });
            }
          });
        }
      });
    },
    gourl: function () {
      var url = '../webpage/webpage';
      uni.navigateTo({
        url: url + '?url=' + e.currentTarget.dataset.text
      });
    },
    goHome: function () {
      uni.switchTab({
        url: '../index/index'
      });
    },
    //获取是否开启评论设置
    getEnableComment: function (id) {
      var self = this;
      var getEnableCommentRequest = wxRequest.getRequest(Api.getEnableComment());
      getEnableCommentRequest.then(response => {
        if (response.data.enableComment != null && response.data.enableComment != '') {
          if (response.data.enableComment === "1") {
            self.setData({
              enableComment: true
            });
          } else {
            self.setData({
              enableComment: false
            });
          }
        }

        ;
      });
    },
	//获取帖子内容
	getTieziid(quanid,tieid,uid,code) {
		
		var self = this;
		self.setData({
		    tiezi: []
		});
		var getTieidRequest = wxRequest.getRequest(Api.getTieid(quanid,tieid,uid,code));
		var res;
		getTieidRequest.then(response => {
			res = response;
			//console.log("帖子",res.data.data.son_tie);
			if(res.data.code) {
				self.jiazai = false;
				self.tiezijiazai = true;
				self.tiezi = res.data.data.son_tie
			} else {
			  uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });
			}
		})
	},
	//获取帖子评论内容
	getPinglunNeirong(tieid,uid,code) {
		//console.log("帖子id",tieids);
		var self = this;
		self.setData({
		    tiezi: []
		});
		var getPinglunNeirongRequest = wxRequest.getRequest(Api.getPinglunNeirong(tieid,uid,code));
		var res;
		getPinglunNeirongRequest.then(response => {
			res = response;
			//console.log("帖子",res.data.data.son_tie);
			if(res.data.code) {
				self.jiazai = false;
				self.tiezijiazai = true;
				self.tiezi = res.data.data.list;
				self.pingluntongji = res.data.data.comments;
				//console.log("帖子tiezi",res.data.data)

			} else {
			  uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });
			}
		})
	},
	//获取帖子内容
	getTiezineirong(tieid,uid,code) {
		//console.log("帖子id",tieids);
		var self = this;
		self.setData({
		    pinglun: []
		});
		var getTiezineirongRequest = wxRequest.getRequest(Api.getPinglunNeirong(tieid,uid,code));
		var res;
		getTiezineirongRequest.then(response => {
			res = response;
			if(res.data.code) {
				self.tiezineirong = res.data.data;
				self.unshenhe = res.data.data.index && res.data.data.index.shenhe;
				self.tieneirong = res.data.data.index && res.data.data.index.neirong;
				if(res.data.data.title){
					self.jubaotitle = res.data.data.title;
				} else {
					self.jubaotitle = res.data.data.index && res.data.data.index.neirong;
				}
				//console.log("self.jubaotitle",self.jubaotitle);
				//console.log("tiezineirong.yunxiazai",self.tiezineirong && self.tiezineirong.yunxiazai);
				//console.log("tiezineirong",res.data.data.index.neirong);
				let tieziindexs = {
					"id": res.data.data.id,
					"touxiang": res.data.data.touxiang,
					"mingcheng": res.data.data.mingcheng,
					"yonghuzu": res.data.data.yonghuzu,
					"guishudi": res.data.data.guishudi,
					"comments": res.data.data.comments,
					"uid": res.data.data.uid
				}
				self.tieziuid = res.data.data.uid;
				//console.log('tieziuid: ',self.tieziuid);
				self.tieziindex = tieziindexs;
				self.getGerenGuanzhus(res.data.data.uid);
				self.getRenzheng(res.data.data.uid);
				//console.log("tieziindex",self.tieziindex);
			} else {
			  uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });
			}
		})
	},
    //获取文章内容
    fetchDetailData: function (id) {
      var self = this;
      var getPostDetailRequest = wxRequest.getRequest(Api.getShowUrl(id));
      var res;
      getPostDetailRequest.then(response => {
        res = response;
		//console.log(res);
        if (response.data.data.code == 0 && response.data.data.status == "404") {
          self.setData({
            showerror: 'block',
            display: 'none',
            errMessage: response.data.message
          });
          return false;
        } // 设置页面标题：文章分类


        uni.setNavigationBarTitle({
          // title: res.data.title.rendered
          title: res.data.data.title
        });
        //WxParse.wxParse('article', 'html', response.data.content.rendered, self, 5)
        setTimeout(() => {
          self.article_article = response.data.data.content;
        }, 200);


        ;
        var _likeCount = response.data.like_count;
        self.setData({
          detail: response.data.data,
          likeCount: _likeCount,
          postID: id,
          link: response.data.data.link,
          detailDate: response.data.data.updatetime,
          display: 'block',
          total_comments: response.data.data.hits,
          postImageUrl: response.data.postImageUrl
        });
        return response.data;
      }).then(response => {
       
      }).catch(function (error) {
        console.log('error: ' + error);
      });
    },
    //拖动进度条事件
    //给a标签添加跳转和复制链接事件
    wxParseTagATap: function (e) {
      var self = this;
      var href = e.currentTarget.dataset.src;
      //console.log(href);
      var domain = config.getDomain; //可以在这里进行一些路由处理

      if (href.indexOf(domain) == -1) {
        uni.setClipboardData({
          data: href,
          success: function (res) {
            uni.getClipboardData({
              success: function (res) {
                uni.showToast({
                  title: '链接已复制',
                  //icon: 'success',
                  image: "/static/images/uploads/link.png",
                  duration: 2000
                });
              }
            });
          }
        });
      } else {
        var slug = util.GetUrlFileName(href, domain);

        if (slug == 'index') {
          uni.switchTab({
            url: '../index/index'
          });
        } else {
          var getPostSlugRequest = wxRequest.getRequest(Api.getPostBySlug(slug));
        }
      }
    },
	//个人关注判断
	getGerenGuanzhus(touid) {
		var duixin = this;
		//console.log('touid: ',touid);
		//var touid = duixin.tieziindex['uid'];
		var getGerenGuanzhuRequest = wxRequest.getRequest(Api.getGerenGuanzhu(duixin.memberuid,duixin.userInfo,touid));
		var res;
		getGerenGuanzhuRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.data.guanzhuuid == 1) {
					duixin.guanzhuuid = res.data.data.guanzhuuid;
				} else {
					duixin.guanzhuuid = 0
				}
				
			}
		})
		
	},
	//关注
	getGuanzhus(index,uid) {
		var duixin = this;
		var getGuanzhuRequest = wxRequest.getRequest(Api.getGuanzhu(duixin.memberuid,duixin.userInfo)+'&uid='+uid);
		var res;
		getGuanzhuRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.data.status == 1) {
					duixin.guanzhuuid = 1;
					
					uni.showToast({
						title: res.data.msg,
						icon: 'success',
						duration: 2000
					});
					
				} else {
					duixin.guanzhuuid = 0;
					
					uni.showToast({
					  title: res.data.msg,
					  mask: false,
					  duration: 1000
					});
				}
				
			} else {
				uni.showToast({
					icon: 'none',
					title: res.data.msg+'关注提示'
				});
			}
		})
	},
    //获取评论
    fetchCommentData: function () {
      
    },
	// 登录校验
	checkLogin() {
		// TODO 此处填写登录校验逻辑
		var userInfo = uni.getStorageSync('userInfo');
		if (userInfo) {
			return true;
		} else {
			uni.showModal({
				title: '提示',
				content: '请先登录',
				confirmText: '前往登录',
				success: function(res) {
					if (res.confirm) {
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}
				}
			});
			return false;
		}
	},
	// 输入框聚焦
	focusOn() {
		this.checkLogin();
	},
	// 新增评论
	add(req,uid,code) {
		
		if (!this.checkLogin()) {
			return
		}
		var that = this;
		//that.fetchDetailData(options.id);
		var skin = uni.getStorageSync('skin');
		var tieids = that.tieids;
		//console.log("帖子ids",tieids);
		//判断用户是否登录
		var userInfo = uni.getStorageSync('userInfo');
		//console.log("options",options);
		if (userInfo) {
			var member = uni.getStorageSync('member');
			var memberuid = uni.getStorageSync('memberuid');
			
		}
		if (that.reqFlag) {
			uni.showToast({
				title: '操作频繁',
				duration: 500
			});
			return
		}
		
		that.reqFlag = true;
		let params = {
			"articleId": that.articleId,
			"pId": req.pId,
			"content": req.content
		}
		
		var datas = "is_ajax=1&content="+that.pingluncontents;
		console.log("req.rid",req);
		var postPinglunRequest = wxRequest.postRequest(Api.postPinglun(req.pId,memberuid,userInfo,req.rid),datas);
		postPinglunRequest.then(response => {
			if (response.data.code == 1) {
			  //console.log('二级评论',req.erjiuid); 
			  uni.showToast({
			  	title: "评论成功",
			  	duration: 1000
			  });
			  that.reqFlag = false;
			  that.$refs.hbComment.addComplete();
			  that.getPinglunNeirong(tieids,memberuid,userInfo);
			  uni.showToast({
			  	title: "更新加载",
			  	duration: 2000
			  });
			  if(req.rid >0){
				  var pinglun_data = '{"type":"pinglun","tieid":"'+tieids+'","uid":"'+that.uid+'","tieuid":"'+that.tieziindex.uid+'","tiename":"2","tozanuid":"'+req.erjiuid+'","tozanname":"'+that.member.name+'","avatar":"'+that.member.avatar+'"}';
				  if(req.erjiuid != that.uid) {
				  	
					/*#ifdef H5*/
					that.duixinim.send(pinglun_data);
					/*#endif*/
					/*#ifdef MP-WEIXIN || APP-PLUS*/
					uni.sendSocketMessage({
					      data: pinglun_data
					});
					/*#endif*/
				  }
			  } else {
				  var pinglun_data = '{"type":"pinglun","tieid":"'+tieids+'","uid":"'+that.uid+'","tieuid":"'+that.tieziindex.uid+'","tiename":"2","tozanuid":"'+that.uid+'","tozanname":"'+that.member.name+'","avatar":"'+that.member.avatar+'"}';
				  if(that.tieziindex.uid != that.uid) {
				  	
					/*#ifdef H5*/
					that.duixinim.send(pinglun_data);
					/*#endif*/
					/*#ifdef MP-WEIXIN || APP-PLUS*/
					uni.sendSocketMessage({
					      data: pinglun_data
					});
					/*#endif*/
				  }
			  }
			  
			} else {
			  uni.showToast({
			  	title: response.data.msg,
			  	duration: 1000
			  });
			}
		});
		// TODO 接入真实接口
		// let params = {
		// 	"articleId": this.articleId,
		// 	"pId": req.pId,
		// 	"content": req.content
		// }
		// this.$u.api.commentAdd(params).then(res => {
		// 	uni.showToast({
		// 		title: '操作成功！',
		// 		duration: 3000
		// 	});
		// 	this.$refs.hbComment.addComplete();
		// 	this.getComment();
		// 	this.reqFlag = false;
		// }).catch(res => {
		// 	this.reqFlag = false;
		// })
		// 下边假装请求成功
		//this.reqFlag = false;
		//this.$refs.hbComment.addComplete();
		//this.getComment();
	},
	//点赞
	getZan(tieziid,uid){
		console.log('getZan',uid); 
		var that = this;
		/*self.setData({
		    pinglun: []
		});*/
		var getZanRequest = wxRequest.getRequest(Api.getZan(tieziid,that.memberuid,that.userInfo));
		var res;
		getZanRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.msg.status == 1) {
					uni.showToast({
						title: res.data.msg.value+' '+res.data.msg.jifen,
						icon: 'success',
						duration: 2000
					});
					that.dianzan = "thumb-up-fill";
					that.getZanzhi(tieziid);
					var zan_data = '{"type":"zan","tieid":"'+tieziid+'","uid":"'+that.uid+'","tieuid":"'+uid+'","tiename":"2","tozanuid":"'+that.uid+'","tozanname":"'+that.member.name+'","avatar":"'+that.member.avatar+'"}';
					
					if(uid != that.uid) {
						
						/*#ifdef H5*/
						that.duixinim.send(zan_data);
						/*#endif*/
						/*#ifdef MP-WEIXIN  || APP-PLUS*/
						uni.sendSocketMessage({
						      data: zan_data
						});
						/*#endif*/
					}
					that.getDianzantongjideta();
				} else {
					uni.showToast({
						title: res.data.msg.value+' '+res.data.msg.jifen,
						icon: 'success',
						duration: 2000
					});
					that.dianzan = "thumb-up";
					that.getZanzhi(tieziid);
					that.getDianzantongjideta();
					
				}
				
			} else {
				that.dianzan = "thumb-up";
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '还没有登录'
			  });*/
			  uni.showModal({
			  	title: '请先登录',
			  	//content: '请先登录',
			  	confirmText: '前往登录',
			  	success: function(res) {
			  		if (res.confirm) {
			  			uni.redirectTo({
			  				url: '/pages/login/login'
			  			});
			  		}
			  	}
			  });
			  //uni.reLaunch({ url: '/pages/login/login'}) // 跳转到登录页
			}
		})
		
	},
	//判断是否点赞
	getZanzhi(tieziid){
		var that = this;
		var getZanRequest = wxRequest.getRequest(Api.getZan(tieziid,that.memberuid,that.userInfo)+'&zan=1');
		var res;
		getZanRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.msg.zanzhi == 1){
					that.dianzan = "thumb-up-fill";
				} else {
					that.dianzan = "thumb-up";
				}
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });*/
			  that.dianzan = "thumb-up";
			}
		})
		
	},
	//收藏heart
	getShoucang(tieziid){
		var that = this;
		/*self.setData({
		    pinglun: []
		});*/
		var getShoucangRequest = wxRequest.getRequest(Api.getShoucang(tieziid,that.memberuid,that.userInfo));
		var res;
		getShoucangRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.msg.status == 1) {
					uni.showToast({
						title: res.data.msg.value+' '+res.data.msg.jifen,
						icon: 'success',
						duration: 2000
					});
					that.shoucang = "heart-fill";
					that.getShoucangzhi(tieziid);
				} else {
					uni.showToast({
						title: res.data.msg.value+' '+res.data.msg.jifen,
						icon: 'success',
						duration: 2000
					});
					that.shoucang = "heart";
					that.getShoucangzhi(tieziid);
					
				}
				
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '还没有登录'
			  });*/
			  that.shoucang = "heart";
			  uni.showModal({
			  	title: '请先登录',
			  	//content: '请先登录',
			  	confirmText: '前往登录',
			  	success: function(res) {
			  		if (res.confirm) {
			  			uni.redirectTo({
			  				url: '/pages/login/login'
			  			});
			  		}
			  	}
			  });
			  //uni.reLaunch({ url: '/pages/login/login'}) // 跳转到登录页
			}
		})
		
	},
	//判断收藏值
	getShoucangzhi(tieziid){
		var that = this;
		var getShoucangzhiRequest = wxRequest.getRequest(Api.getShoucang(tieziid,that.memberuid,that.userInfo)+'&shoucang=1');
		var res;
		getShoucangzhiRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.msg.shoucangzhi == 1){
					that.shoucang = "heart-fill";
				} else {
					that.shoucang = "heart";
				}
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });*/
			  that.shoucang = "heart";
			}
		})
		
	},
	//用户认证
	getRenzheng(uid){
		var duixin = this;
		var getRenzhengszhiRequest = wxRequest.getRequest(Api.getRenzhengs(uid));
	    var res;
		getRenzhengszhiRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.code == 1){
					duixin.rzs = res.data.data.rzs[0];
					//console.log('认证：',duixin.rzs);
				} else {
					
				}
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });*/
			  that.shoucang = "heart";
			}
		})
	},
	// 评论内容
	pingluncontent(e){
		var duixin = this;
		duixin.pingluncontents = e;
		//console.log('pinglun',e)
	},
	//获取当前页面
	getDangqianurl() {
		//获取当前页面栈的实例
		let pages = getCurrentPages();
		//获取当前页面
		let currentPage = pages[pages.length-1].$page.fullPath;
		let url = currentPage;
		uni.setStorageSync('dangqianUrl', url);
	},
	// 个人页面
	getgeren(uid) {
		
		var url = '../u/index?&uid='+uid;
		uni.navigateTo({
			url: url
		});
	},
	//阅读图片
	showimgs(e){
		var duixin = this;
		var urls = duixin.tiezineirong.jiugetu;
		var urlsimg = [];
		for (let i = 0; i < urls.length; i++) {
			urlsimg[i] = urls[i].url
		}
		uni.previewImage({
		  urls: urlsimg,
		  current: e
		});
	},
	//进度条
	getJindus(id) {
		var duixin = this;
		var getJinduRequest = wxRequest.getRequest(Api.getJindu(id));
		var res;
		getJinduRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.code == 1){
					duixin.jindu = res.data.data;
				} else {
					
				}
			} else {

			  that.shoucang = "heart";
			}
		})
	},
	// 下载
	xiazaifujian(){
		
	},
	//附件url
	fujianurl(url){
		console.log("附件url",url);
		uni.showLoading({title: '正在下载……'});
		/*#ifdef H5*/
		window.location.href = url;
        uni.hideLoading();
		uni.showToast({
			icon: 'none',
			mask: true,
			title: '文件已保存', 
			duration: 3000,
		});
		/*#endif*/
		/*#ifdef MP-WEIXIN || APP-PLUS*/
		uni.showLoading({title: '正在下载……'});
		uni.downloadFile({
				url: url,//下载地址接口返回
				success: (res) => {
					console.log('打印data',res)
					uni.hideLoading();
					//文件保存到本地
					if (res.statusCode === 200) {
						//保存文件
						let tempFile = res.tempFilePath;
						
						/*#ifdef APP-PLUS */
						//保存到本地
						uni.saveFile({
							tempFilePath: res.tempFilePath,//文件的临时路径
							success: function(res) {
								const savedFilePath = res.savedFilePath;
								// 打开文件
								uni.openDocument({
									filePath: savedFilePath,
									success: function(res) {
										uni.hideLoading()
									},
									fail: function(res) {},
									complete: function(res) {
										setTimeout(uni.hideLoading(), 4000)
									},
								});
							},
							fail: function(err) {	}
						});
						/*#endif*/
						/*#ifdef MP-WEIXIN*/
						//保存成功之后 打开文件
						uni.getFileSystemManager().saveFile({
						tempFilePath: tempFile,
						// filePath: wx.env.USER_DATA_PATH + '/' + '上传成员.pdf',//自定义文件名
						success(res) {
							uni.showToast({
								icon: 'none',
								mask: true,
								title: '文件已保存', 
								duration: 3000,
							});
							/*console.log(res)
								uni.openDocument({
									filePath: res.savedFilePath,
									showMenu: true, //是否可以分享
									success: (res) => {
										uni.hideLoading()
										console.log(res);
									},
									fail: (e) => {
										uni.showToast({
											title: '打开失败',
											icon: "error"
										})
									}
								})*/

							}
						})
						/*#endif*/
					}
				},
				fail: (e) => {
					console.log(e, '文件下载失败')
					uni.showToast({
						title: '文件下载失败',
						icon: "error",
					})
				}

			
			});
		/*#endif*/

	},
	yunurl(url,ma) {
		//console.log("附件url",url);
		uni.setClipboardData({
		  data: url+' 认证码:'+ma,
		  success: () => {
		    uni.showToast({
		      title: '复制成功'
		    });
		  },
		  fail: () => {
		    uni.showToast({
		      title: '复制失败.未开通权限',
		      icon: 'none'
		    });
		  }
		});
	},
	jubao(id) {
		console.log("id",id);
	},
	jubaoclose(){
		this.jubaoshow = false
	},
	jubaoopen(){
		var duixin = this;
		duixin.jubaoshow = true
		//console.log("id");
	},
	postJubao(id){
		console.log("postJubao",id);
	},
	checkboxChange(n) {
		this.jubaoxuanzedata = n;
	},
	//重新链接
	getimin(uid,member){
		var duixin = this;
		
		if (!duixin.duixinimin || duixin.duixinimin.readyState == 3) { 
			/*#ifdef H5*/
			duixin.duixinimin = new WebSocket(wss);  
			  
			duixin.duixinimin.onopen = () => {  
			  console.log('im连接成功',duixin.duixinim);  
			  duixin.message = '已连接';
			  var login_data = '{"type":"login","name":"'+member.name+'","uid":"'+uid+'"}';
			  console.log("登录成功，发送登录数据:"+login_data);
			  duixin.duixinim.send(login_data);
			};  
			  
			duixin.duixinimin.onmessage = duixin.getOnmessage;  
			  
			duixin.duixinimin.onclose = function(event) {
			  console.log('im已关闭，尝试重新连接...', event);
			  duixin.message = '连接已断开';  
			  setTimeout(() => {  
				duixin.getimin(); // 延迟重新连接，避免频繁尝试连接
				console.log('im连接成功in'); 
			  }); // 5秒后重新连接  , 5000
			};  
			duixin.duixinimin.onerror = function(error) {  
			  console.error('im错误:', error);  
			}; 
			/*#endif*/
			/*#ifdef MP-WEIXIN  || APP-PLUS*/
			uni.connectSocket({
			  url: wss,
			  success(data) {
			     console.log("websocket连接成功",data);
			  },
			  fail(err) {
				console.error('WebSocket连接失败', err);
			  }
			});
			uni.onSocketOpen(function (res) {
			  console.log('WebSocket连接已打开！');
			  var login_data = '{"type":"login","name":"'+member.name+'","uid":"'+uid+'"}';
			    uni.sendSocketMessage({
			        data: login_data
			    });
			});
			uni.onSocketMessage(function (res) {
			  console.log('收到服务器内容：' + res.data);
			  duixin.getOnmessage(res);
			});
			uni.onSocketClose(function (res) {
			  console.log('WebSocket 已关闭！');
			  setTimeout(() => {
				duixin.getimin(); // 延迟重新连接，避免频繁尝试连接
				console.log('im连接成功in'); 
			  }); // 5秒后重新连接  , 5000
			});
			uni.onSocketError(function (res) {
			  console.log('WebSocket连接打开失败，请检查！');
			});
			/*#endif*/
		} else {  
		console.log('im连接已存在');  
		} 
	},
	getOnmessage(e){
		var duixin = this;
		//console.log('收信息',e.data);
		var shouxin = JSON.parse(e.data); 
		duixin.shouxin = shouxin;
		if(shouxin.type == 'zan') {
			if(duixin.uid==shouxin.tieuid){
				duixin.toptishishow = true;
				duixin.dianzanname = shouxin.tozanname;
				duixin.dianzantouxiang = shouxin.avatar;
				duixin.duanxintongzhi = 1;
				duixin.getTongjis(duixin.uid);
				setTimeout(() => {  
					duixin.toptishishow = false; // 五秒后隐藏
				}, 3000); // 延迟时间为 5000 毫秒（即 5 秒）
			}
			
		}
	},
	//获取消息统计
	getTongjis(uid) {
	  	var self = this;
	  	//console.log('xx'); 
	  	var getXiaoxitongjiRequest = wxRequest.getRequest(Api.getXiaoxitongji(uid));
	  	getXiaoxitongjiRequest.then(response => {
	  		if (response.data.code == 1) {
	  		  //console.log(response.data.data); 
	  		  self.tongji = response.data.data
			  self.tongzhis(response.data.data);
	  		} else {
	  		  self.setData({
	  			displaySwiper: "none"
	  		  });
	  		}
	  	});
	},
	// 通知
	tongzhis(e){
		var tongjishu = e;
		
	},
	//举报
	postJubaodata(id){
		var duixin = this;
		let pages = getCurrentPages();  
		let currentPage = pages[pages.length - 1];  
		let url = currentPage.route; // 当前页面的路由地址

		var wangzhi = url+'?qid='+duixin.qid+'&id='+duixin.tieids;
		var shuoming = duixin.jubaoData.neirong;
		if(!shuoming) {
			uni.showToast({
				title: '填写举报内容',
				icon: "error",
			})
		}
		var n = duixin.jubaoxuanzedata;
		if(!n.length) {
			uni.showToast({
				title: '选择标签',
				icon: "error",
			})
		}
		var jubaoshuju=[];
		for (var i = 0; i < n.length; i++) {
            jubaoshuju[i]={};
		  if (n[i] == '广告') {
			  this.jubaoshuju.wenti1 = 1; 
			  jubaoshuju[i].cid = this.jubaoshuju.wenti1;
			  
		  }
		  if (n[i] == '重复') {
		  		this.jubaoshuju.wenti2 = 2; 
				jubaoshuju[i].cid = this.jubaoshuju.wenti2;
		  		
		  }
		  if (n[i] == '低俗') {
		  		this.jubaoshuju.wenti3 = 3; 
				jubaoshuju[i].cid = this.jubaoshuju.wenti3;
		  		
		  }
		  if (n[i] == '夸张') {
		  		this.jubaoshuju.wenti4 = 4; 
				jubaoshuju[i].cid = this.jubaoshuju.wenti4;
		  		
		  }
		}
		let wenti = '';
		jubaoshuju.forEach(item=>{
			wenti+= '&data[wenti][]='+item.cid;
		})
		var datas = "is_ajax=1&catid=1&data[wangzhi]="+wangzhi+"&data[shuoming]="+shuoming+wenti;
		console.log('datas',datas); 
		var postJubaoRequest = wxRequest.postRequest(Api.postJubao(duixin.uid,duixin.userInfo,duixin.tieids),datas);
	    postJubaoRequest.then(response => {
			if (response.data.code == 1) {
				uni.showToast({
					title: response.data.msg,
					icon: 'success',
					duration: 5000
				});
				}
				duixin.jubaoshow = false;
				duixin.jubaoData.neirong = '';
				duixin.jubaoxuanzedata = [];
			});
	},
	//点赞统计
	getDianzantongjideta(){
		
		var duixin = this;
		var getDianzantongjiRequest = wxRequest.getRequest(Api.getDianzantongji(duixin.tieids));
		var res;
		getDianzantongjiRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.code == 1){
					duixin.dianzandata = res.data.data;
					if(res.data.data[0]){
						duixin.dianzanshu = res.data.data[0].dianzanshu;
					} else {
						var tongji = duixin.dianzanshu-1;
						if(tongji == -1){
							duixin.dianzanshu = 0;
						} else {
							duixin.dianzanshu = tongji;
						}
					}
					
				} else {
				}
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });*/
			}
		})
	},
	//圈子
	getQuan(id){
		var url = '../quan/quanzi?id=' + id;
		uni.navigateTo({
				url: url
		});
	},
	//审核帖子
	shenhe(e) {
		console.log('shenhe', e);
		if(e ==1){
			this.shenheshow = true;
		}
	},
	//审核关闭
	shenheguanbi(){
		this.shenheshow = false;
	},
	//审核确认
	shenhequerren(){
		this.getShenhequeren();
	},
	//审核确认接口
	getShenhequeren(){
		var duixin = this;
		var getShenhetieziRequest = wxRequest.getRequest(Api.getShenhetiezi(duixin.memberuid,duixin.keycode,duixin.tieids));
		var res;
		getShenhetieziRequest.then(response => {
			res = response;
			if(res.data.code) {
				if(res.data.msg.status == 1){
					uni.showToast({
						title: res.data.msg.value,
						icon: 'success',
						duration: 2000
					});
					this.shenheshow = false;
					duixin.unshenhe =1;
				} else {
					
				}
			} else {
			  /*uni.showToast({
			  	icon: 'none',
			  	title: '获取失败，请稍后重试'
			  });*/
			  
			}
		})
	},
	//点赞评论
	like(){
		
	},
	//删除评论
	del(){
		
	}
  }
};
</script>
<style>
@import "../tiezi/tiezi.css";
/* #ifdef H5 */
::v-deep img {
    max-width: 100%;
	border-radius: 10px;
}
::v-deep p {
	    display: block;
	    margin-top: 5px;
		margin-bottom:5px;
		line-height:30px !important;
		font-size: 18px;
} 
::v-deep pre {
	padding: 10px;
	background-color: #262626;
	border-radius: 10px;
	color: #eaeaea;
}
/* #endif */

</style>